<template>
  <div>
    <div class="header" v-if="!show">
      <van-icon name="arrow-left" size="0.6rem" @click="goback" />
      <span>题库选择</span>
    </div>

    <!-- 搜索 -->
    <van-search
      v-model="value"
      shape="round"
      show-action
      @blur="searchWord(value)"
      placeholder="请输入题库名称搜索关键词"
    >
      <template #action>
        <div @click="quxiao">取消</div>
      </template>
    </van-search>

    <div class="list-box" v-if="!show">
      <!-- 侧边栏 -->
      <van-sidebar v-model="activeKey">
        <van-sidebar-item
          @click="onChange(item.id)"
          :title="item.name"
          v-for="item in left"
          :key="item.id"
        />
      </van-sidebar>

      <!-- 右边内容 -->
      <div class="right">
        <div class="right-item" v-for="item in right" :key="item.id">
          <p>{{item.name}}</p>
          <div v-for="i in item.bank" :key="i.id" class="children">
            <p>{{i.name}}</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 搜索显示区域 -->
    <div v-show="show && isShow" v-for="item in searchList" :key="item.id" class="searchList">
      <p>{{item.name}}</p>
    </div>

    <div v-if="!isShow">没有搜到相关内容</div>
  </div>
</template>
<script>
import { djhLeft, djhRight, djhSearch } from "../util/http";
export default {
  name: "",
  components: {},
  props: [],
  data() {
    return {
      value: "",
      activeKey: 0,
      left: [],
      right: [],
      commingFist: "",
      searchList: [],
      show: false,
      isShow: -1
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getLeft();
  },
  mounted() {},
  methods: {
    goback() {
      this.$router.push("/practise");
    },
    //侧边栏
    getLeft() {
      djhLeft().then(res => {
        // console.log(res);
        this.left = res;
        if (this.commingFist == "") {
          this.commingFist = res[0].id;
          djhRight({ id: this.commingFist }).then(res => {
            // console.log(res);
            this.right = res;
          });
        }
        // console.log(this.commingFist);
      });
    },

    //点击侧边栏显示数据
    onChange(id) {
      djhRight({ id: id }).then(res => {
        console.log(res);
        this.right = res;
      });
    },

    //搜索
    async searchWord(value) {
      const res = await djhSearch(value);
      // console.log(res);
      this.show = true;

      if (res.length == 0) {
        this.isShow = false;
      } else {
        this.isShow = true;
        this.searchList = res;
        this.qu = true;
      }
    },
    //取消
    quxiao() {
      this.show = false;
    }
  }
};
</script>
<style scoped lang="scss">
.header {
  width: 100%;
  // height: 30px;
  // line-height: 30px;
  .van-icon {
    margin: 5px;
  }
  span {
    font-size: 20px;
    display: inline-block;
    margin-left: 32%;
  }
}

.list-box {
  width: 100%;
  position: relative;
  border-top: 1px solid #eee;
}

.van-sidebar {
  overflow: auto;
  height: 90vh;
  background-color: #fafafa;
}

.right {
  position: absolute;
  width: 80%;
  top: 0;
  right: 0;
  height: 90vh;
  overflow: scroll;
  .right-item {
    margin: 20px 0 20px 20px;
    p:nth-child(1) {
      font-size: 12px;
    }
    .children {
      background-color: #eee;
      font-size: 14px;
      width: 120px;
      height: 30px;
      line-height: 30px;
      text-align: center;
      margin-top: 10px;
    }
    .children:hover {
      background-color: #fdefe5;
      color: orangered;
    }
  }
}

.searchList {
  p {
    border-bottom: 1px solid #eee;
    font-size: 14px;

    margin: 10px;
  }
}
</style>